package ysc.cqnu.operdb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import ysc.cqnu.operdb.entity.ResultData;
import ysc.cqnu.operdb.entity.Tailor;
import ysc.cqnu.operdb.mapper.CaiJianMapper;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin
@Controller
@ResponseBody
public class EnterCaiJianInfoShowController {
    @Autowired
    private ResultData resultData;
    @Autowired
    private CaiJianMapper caiJianMapper;
    @RequestMapping(value = "/caijiandetails",method = RequestMethod.GET)
    public ResultData caijiandetails(@RequestParam("Index") String Index){
        System.out.println("裁剪分页已连接");
        List<Tailor> list = new ArrayList<>();
        Integer index = Integer.valueOf(Index);
        Integer begin;
        Integer end;
        Integer count = caiJianMapper.count();
        if(index<=1){
            begin=0;
            end=5;
            list = caiJianMapper.fenye(begin,end);
            resultData.data=list;
            resultData.flag="yes";
            return resultData;
        }
        if(index*5>count){
            begin = count-count%5;
            end = count%5;
            list = caiJianMapper.fenye(begin,end);
            resultData.data=list;
            resultData.flag="yes";
            return resultData;
        }
        else {
            begin = (index-1)*5;
            end = 5;
            list = caiJianMapper.fenye(begin,end);
            resultData.data=list;
            resultData.flag="yes";
            return resultData;
        }
    }
}
